var vm_qushiquerenmanage = new Vue({
    el: "#qushiquerenmanage",
    data: {
        deptid: $("#deptid").val(),		// deptid
        qushiquerenlist: [],// 趋势确认列表custom
        piciid: $("#piciid").val(),//去世确认批次id
        qushiqueren: {},//去世确认
        zhanghuxinxi:{},//专家信息
        zhanghaoxinxiList:[],

        //查询用字段
        danweimingcheng: "",
        danweicengji: "",
        zhuanjiaxingming: "",
        gongzuodanwei: "",
        shifoubiandong: "",
        shifouchuli: "",
        chuliriqi: "",

        pageindex: 1,		// 查询分页初始化页
        pagesize: 10,		// 查询分页初始化页面大小
        pageCount: 0,		// 总页数
        recordCount: 0,	// 总记录数
        targetpage: '', 	// 目标页

        qushiquerens: [],//导入用

    },
    created: function () {
        var _this = this;
        _this.bindQushiquerenDeptList();

    },
    watch: {
        //监控分页情况，刷新列表
        pageindex: function () {
            this.bindQushiquerenDeptList();
        },

        pagesize: function () {
            this.bindQushiquerenDeptList();
        },
    },
    methods: {

        bindQushiquerenDeptList: function () {
            var _this = this;

            $.post('/system/zhuanjiaqushiqueren/qushiquerenmanagelist', {
                piciid: _this.piciid,
                danweimingcheng: _this.danweimingcheng,
                danweicengji: _this.danweicengji,
                zhuanjiaxingming: _this.zhuanjiaxingming,
                gongzuodanwei: _this.gongzuodanwei,
                shifoubiandong: _this.shifoubiandong,
                shifouchuli: _this.shifouchuli,
                chuliriqi: _this.chuliriqi,
                pageindex: _this.pageindex,
                pagesize: _this.pagesize,
            }, function (ppData) {
                if (ppData.result == "1") {
                    var data = ppData.resultContent;
                    _this.qushiquerenlist = data.list;

                    var pageInfo = data.PageInfo;
                    _this.pageindex = pageInfo.pageIndex;
                    _this.pageCount = pageInfo.pageCount;
                    _this.recordCount = pageInfo.recordCount;
                    _this.targetpage = '';

                }
            }, "json");
        },
        getDate_chuliriqi: function () {
            var _this = this;

            _this.chuliriqi = $("#chuliriqi").val();
        },
        //首页
        firstPage: function () {
            this.pageindex = 1;
        },
        //尾页
        lastPage: function () {
            this.pageindex = this.pageCount;
        },
        //上一页
        prePage: function () {
            var prePage = ((this.pageindex - 1) <= 0) ? 1 : (this.pageindex - 1);
            this.pageindex = prePage;
        },
        //下一页
        nextPage: function () {
            var nextPage = ((this.pageindex + 1) >= this.pageCount) ? this.pageCount : (this.pageindex + 1);
            this.pageindex = nextPage;
        },
        //跳到目标页
        targetPage: function () {
            if (this.targetpage != '' && this.targetpage <= this.pageCount && this.targetpage > 0) {
                this.pageindex = this.targetpage;
                this.targetpage = '';
            }
        },

        reset: function () {
            var _this = this
            _this.danweimingcheng = "",
            _this.danweicengji = "",
            _this.zhuanjiaxingming = "",
            _this.gongzuodanwei = "",
            _this.shifoubiandong = "",
            _this.shifouchuli = "",
            _this.chuliriqi = "",
            _this.bindQushiquerenDeptList()
        },
        toLianxifangshi:function (zhuanjiaitem) {
            var _this = this;
            _this.zhanghuxinxi = zhuanjiaitem

            $.post('/system/deptdetail/Zhanghaoxinxi', {
                deptid: zhuanjiaitem.jigoudaima,
                rdm: Math.random()
            }, function (ppData) {
                if (ppData != null) {
                    var data = ppData.resultContent;
                    _this.zhanghaoxinxiList = data;
                }
            }, "json");

            $("#myModalLabel2").html("专家及相关层级经办人联系方式");
            $("#lianxifangshiModal").modal();
        },

        // 显示上传xls的模态框
        showUploadXls: function () {
            var _this = this;

            $("#uploadModal").modal("show");
            this.getFileUrl("qushiqueren", '51200', 'xls,xlsx');
        },

        // 将文件上传到指定地址,并接受返回过来的路径，
        getFileUrl: function (ppFolderName, ppFileSize, ppShangChuanWenJianLeiXing) {
            var _this = this;
            // load上传项目
            $("#uploadModal-body").load("/system/page/upload_batch?fujianpath=/userfiles/" + ppFolderName + "&filesize=" + ppFileSize, function () {
                UploadVue.Init(ppShangChuanWenJianLeiXing, ppFileSize + "kb", function (jsonList) {
                    if (jsonList.length == 0) {
                        return;
                    }
                    var filename = jsonList[0].filename;
                    var fileurl = jsonList[0].fileurl;
                    var filesize = jsonList[0].filesize;
                    _this.getValue(fileurl);
                }, function () {
                    $("#uploadModal").modal("hide");
                });
            });
        },

        //
        getValue: function (ppFileurl) {
            var _this = this;
            layer.open({type: 3});

            $.post("/system/zhuanjiaqushiqueren/get_value", {
                fileurl: ppFileurl,
                random: Math.random()
            }, function (ppData) {
                layer.closeAll("loading");
                if (ppData != null) {
                    var mmData = ppData;
                    var result = mmData.result;
                    var message = mmData.message;
                    var data = mmData.resultContent;

                    if (result == "1") {
                        $(".daoruzhuangtai").html("");
                        _this.qushiquerens = data;

                        $("#uploadModal").modal("hide");
                        $("#QushilistModal").modal("show");

                    } else {
                        layer.alert(message);
                    }
                }
            }, "json");
        },

        // 批量导入项目目录
        importQushi: function () {
            var _this = this;

            layer.confirm("确定要导入所有专家去世确认名单吗？", {
                btn: ["是", "否"]
            }, function () {
                layer.closeAll("dialog");
                // 开始批量导入
                _this.startDaoru();
            });
        },

        // 批量导入
        startDaoru: function () {
            var _this = this;
            layer.open({type: 3});
            $("#daoru").attr("disabled", "disabled");
            //从待导入专家第一个开始导入
            _this.daoru(0);
        },

        // 单个导入
        daoru: function (ppQushiquerenCurrentIndex) {

            layer.open({type: 3});
            var _this = this;

            var CurrentIndex = ppQushiquerenCurrentIndex + 1;

            layer.open({
                type: 3,
                content: "<div style='font-size:18px;font-weight:bold;padding-top:40px;width:200px;text-align:left;'>正在导入专家去世确认名单<br/>当前进度    " + CurrentIndex + " / " + _this.qushiquerens.length + "</div>"
            });

            $.post("/system/zhuanjiaqushiqueren/import", {
                piciid : _this.piciid,
                zhuanjiaid: _this.qushiquerens[ppQushiquerenCurrentIndex].专家ID,
                xingming: _this.qushiquerens[ppQushiquerenCurrentIndex].姓名,
                jigoudaima: _this.qushiquerens[ppQushiquerenCurrentIndex].单位代码,
                suoshudanwei: _this.qushiquerens[ppQushiquerenCurrentIndex].所属单位,
                gongzuodanwei: _this.qushiquerens[ppQushiquerenCurrentIndex].工作单位,
                shenfenzhenghao: _this.qushiquerens[ppQushiquerenCurrentIndex].身份证号,
                siwangbiaoji: _this.qushiquerens[ppQushiquerenCurrentIndex].死亡标识,
                siwangriqi: _this.qushiquerens[ppQushiquerenCurrentIndex].死亡日期,
                beizhu: _this.qushiquerens[ppQushiquerenCurrentIndex].备注,
                random: Math.random()
            }, function (ppData) {
                layer.closeAll("loading");

                if (ppData.result == "0") {
                    // 未成功导入
                    $("#" + (ppQushiquerenCurrentIndex + 1)).html("<span style='color:red;'>" + ppData.message + "</span>");
                    if (ppQushiquerenCurrentIndex >= _this.qushiquerens.length - 1) {
                        layer.alert("导入完成！");
                    } else {
                        ppQushiquerenCurrentIndex++;// 待导入高校下标+1

                        _this.daoru(ppQushiquerenCurrentIndex);
                    }

                    $("#daoru").removeAttr("disabled");
                } else {
                    //成功导入
                    $("#" + (ppQushiquerenCurrentIndex + 1)).html("<span style='color:green;'>导入成功</span>");
                    if (ppQushiquerenCurrentIndex >= _this.qushiquerens.length - 1) {
                        $("#daoru").removeAttr("disabled");
                        layer.alert("导入完成！");

                        _this.bindQushiquerenDeptList();

                    } else {
                        ppQushiquerenCurrentIndex++;// 待导入高校下标+1

                        _this.daoru(ppQushiquerenCurrentIndex);
                    }
                }
            }, "json")
        },

        // 单个手动导入
        dangedaoru: function (ppQushi, ppIndex) {
            var _this = this;

            layer.confirm("确定要导入该条专家去世核查信息吗？", {
                btn: ["是", "否"]
            }, function () {
                layer.open({type: 3});
                $.post("/system/zhuanjiaqushiqueren/import", {
                    zhuanjiaid: ppQushi.专家ID,
                    xingming: ppQushi.姓名,
                    jigoudaima: ppQushi.单位代码,
                    suoshudanwei: ppQushi.所属单位,
                    gongzuodanwei: ppQushi.工作单位,
                    shenfenzhenghao: ppQushi.身份证号,
                    siwangbiaoji: ppQushi.死亡标识,
                    siwangriqi: ppQushi.死亡日期,
                    beizhu: ppQushi.备注,
                    random: Math.random()
                }, function (ppData) {
                    layer.closeAll("loading");

                    if (ppData.result == "0") {
                        layer.alert(ppData.message);
                        $("#" + ppIndex).html("<span style='color:red;'>" + ppData.message + "</span>");
                    } else {
                        layer.alert("导入成功！");
                        $("#" + ppIndex).html("<span style='color:green;'>导入成功</span>");
                    }
                }, "json")
            })
        },


    },
})